﻿<?php
/**
 * 删除用户结果
 * @author kinet <380511703@qq.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */

session_start();
require_once( 'path.php');
require_once( SOJ_ROOT.'/include/function/lib.php');

$tpl = new my_smarty();

//若未登录,则重定向到登录界面
if( empty($_SESSION['admin']) ){

	$_SESSION['success_message'] = 'do not login yet , '.$_SESSION['admin'];
	header( 'Location:../manager/manager_login.php' );
	exit ;
}
$request = $_GET;

if( empty( $request['jno'])||empty($request['username'])||empty($request['file'])||empty($request['op']) ){
	//problem,直接跳转到problem页面
	header( 'Location:../manager/manager_index.php');
	exit ;
}else{
	$no =$request['jno'];
	$op =$request['op'];
	$username=$request['username'];
	$code_file_name=$request['file'];
}


//处理由其他页面保存在会话中的错误信息
if( !empty($_SESSION['errors']) ){

	$tpl->assign( 'errors' , $_SESSION['errors']  );
	//清除之前的错误信息
	unset( $_SESSION['errors'] );
}
$tpl->assign('admin', $_SESSION['admin']);


try{
	  $db = db_connect();	
      if($op==1){	  //删除记录
		  judge_result_process::delete_by_judge_no($db,$no);
		  //如果是没有关于代码的记录了就删除代码
		  if(judge_result_process::if_none($db,$code_file_name)){
			code_process::delete_code_file_name($db,$code_file_name);
		  }
	  }
	  else if($op==='all'){//删除代码//删除所有的关于这个代码的记录
	    judge_result_process::delete_by_code_file_name($db,$code_file_name);
		code_process::delete_code_file_name($db,$code_file_name);
	  }
	  header( 'Location:../manager/manager_user_problems.php?name='.$username );
}catch(Exception $e){
	  echo $e->getMessage();
}
